package jdbc.three.UI;

import jdbc.three.beans.Request;
import jdbc.three.controller.AccountCtrl;

import java.util.Scanner;

public class MyUi {
    public MyUi() {
        AccountCtrl c=new AccountCtrl();
        System.out.println("欢迎进入银行系统");
        int mode=-1;
        Scanner in=new Scanner(System.in);
        Request r=new Request();
        while (true){
            System.out.println("选择你要执行的操作：1开户，2查询，3转帐，4退出");
            mode=in.nextInt();
            switch (mode){
                case 1://开户
                    System.out.println("输入帐号，用户名，余额，逗号隔开 ");
                    String[]arr=in.next().split(",");
                    r.setParameter("id",arr[0]);
                    r.setParameter("name",arr[1]);
                    r.setParameter("money",arr[2]);
                    System.out.println(c.register(r));
                    break;
                case 2://查询
                    System.out.println("输入账号：");
                    String id=in.next();
                    r.setParameter("id",id);
                    System.out.println("余额："+c.queryMoney(r));
                    break;
                case 3://转帐
                    System.out.println("你的帐号：");
                    r.setParameter("from",in.next());
                    System.out.println("对方的帐号：");
                    r.setParameter("to",in.next());
                    System.out.println("转多少钱？");
                    r.setParameter("money",in.next());
                    System.out.println(c.transfer(r));
                    break;
                case 4:
                    return;

            }
        }
    }

    public static void main(String[] args) {
        new MyUi();
    }

}
